package org.naxx.security.model.expression;

import java.util.List;

import org.naxx.security.expression.Node;
import org.naxx.security.expression.Node.NodeType;
import org.naxx.security.function.FunctionType;

@SuppressWarnings("unused")
public class TreeExecutor {

	public void execute(Node root) {
	}
	
	private void process(Node node) {
		if(node.getNodeType().equals(NodeType.LEAF)) {
			// noop
		}
		else {
			for(Node child : node.getChildren()) {
				process(child);
			}
			FunctionType function = node.getFunctionType();
			Object[] parameters = this.toArray(node.getChildren());
//			Object value = function.execute(parameters);
//			node.setValue(value);
//			node.reduce();
		}
	}
	
	private Object[] toArray(List<Node> nodes) {
		Object[] result = new Object[nodes.size()];
		int index  = 0;
		for(Node node : nodes) {
			Object value = null;
			if(node.getFunctionType() != null) {
				value = node.getFunctionType(); // higher order function
			}
			else {
//				value = node.get();
			}
			result[index] = value;
			index++;
		}
		return result;
	}
}
